]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
overviewControls: Use specialized class for Overview adjustment
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Fri, 15 Jan 2021 18:28:23 +0000 (15:28 -0300)
committerMarge Bot <marge-bot@gnome.org>
Thu, 11 Feb 2021 15:50:31 +0000 (15:50 +0000)
It'll be useful for the next commits to have a handy 'getState' method
that calculates the progress of any particular transition.

Move the St.Adjustment to a specialized subclass.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1624>

js/ui/overviewControls.js

index c0998983b1043bf6581b0b7be034b6e67f66580c..64edcd7631ab7dcba4deafe759d13b1131e4201f 100644 (file)
@@ -75,6 +75,51 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
     }
 });
 
+var OverviewAdjustment = GObject.registerClass(
+class OverviewAdjustment extends St.Adjustment {
+    _init(actor) {
+        super._init({
+            actor,
+            value: ControlsState.WINDOW_PICKER,
+            lower: ControlsState.HIDDEN,
+            upper: ControlsState.APP_GRID,
+        });
+    }
+
+    getStateTransitionParams() {
+        const currentState = this.value;
+
+        const transition = this.get_transition('value');
+        let initialState = transition
+            ? transition.get_interval().peek_initial_value()
+            : currentState;
+        let finalState = transition
+            ? transition.get_interval().peek_final_value()
+            : currentState;
+
+        if (initialState > finalState) {
+            initialState = Math.ceil(initialState);
+            finalState = Math.floor(finalState);
+        } else {
+            initialState = Math.floor(initialState);
+            finalState = Math.ceil(finalState);
+        }
+
+        const length = Math.abs(finalState - initialState);
+        const progress = length > 0
+            ? Math.abs((currentState - initialState) / length)
+            : 1;
+
+        return {
+            transitioning: transition !== null,
+            currentState,
+            initialState,
+            finalState,
+            progress,
+        };
+    }
+});
+
 var ControlsManager = GObject.registerClass(
 class ControlsManager extends St.Widget {
     _init() {
@@ -118,12 +163,7 @@ class ControlsManager extends St.Widget {
             upper: workspaceManager.n_workspaces,
         });
 
-        this._stateAdjustment = new St.Adjustment({
-            actor: this,
-            value: ControlsState.WINDOW_PICKER,
-            lower: ControlsState.HIDDEN,
-            upper: ControlsState.APP_GRID,
-        });
+        this._stateAdjustment = new OverviewAdjustment(this);
 
         this._nWorkspacesNotifyId =
             workspaceManager.connect('notify::n-workspaces',